package com.tsing.wms.controller;

import com.tsing.wms.service.IRegionService;
import com.tsing.wms.util.ResultUtil;
import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.valid.UpdateGroup;
import com.tsing.wms.vo.PageResultVO;
import com.tsing.wms.vo.ResultData;
import com.tsing.wms.vo.req.IdReqVO;
import com.tsing.wms.vo.req.IdsReqVO;
import com.tsing.wms.vo.req.RegionPageReqVO;
import com.tsing.wms.vo.req.RegionReqVO;
import com.tsing.wms.vo.resp.RegionRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 供应商地区表 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2022-04-13
 */
@Api(tags = "区域管理")
@RestController
@RequestMapping("/region")
public class RegionController {

    @Autowired
    private IRegionService regionService;

    @PostMapping("/addRegion")
    @ApiOperation(value = "新增区域")
    public ResultData addRegion(@Validated({AddGroup.class}) @RequestBody RegionReqVO reqVO, HttpServletRequest request) {
        regionService.addRegion(reqVO, request);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteRegion")
    @ApiOperation(value = "删除区域")
    public ResultData deleteRegion(@Validated @RequestBody IdsReqVO reqVO, HttpServletRequest request) {
        regionService.deleteRegion(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/getRegion")
    @ApiOperation(value = "查询地区详情")
    public ResultData<RegionRespVO> getRegion(@Validated IdReqVO reqVO) {
        return ResultUtil.success(regionService.getRegion(reqVO));
    }

    @PutMapping("/updateRegion")
    @ApiOperation(value = "修改区域")
    public ResultData updateRegion(@Validated({UpdateGroup.class}) @RequestBody RegionReqVO reqVO, HttpServletRequest request) {
        regionService.updateRegion(reqVO, request);
        return ResultUtil.success();
    }

    @GetMapping("/regionPage")
    @ApiOperation(value = "区域分页")
    public ResultData<PageResultVO<RegionRespVO>> regionPage(@Validated RegionPageReqVO reqVO) {
        return ResultUtil.success(regionService.regionPage(reqVO));
    }

}
